import numpy as np
import matplotlib.pyplot as plt
import pylab
def display_val_time(val,ti,sttime):
    '''
    x/y:time/value ,sttime means the date to do the measurement
    '''
    x = [] ; y = []
    for i in range(0,len(val)):
        x.append(i)
        y.append(val[i])
    fig,ax = plt.subplots()

    xticks = range(0,len(val),1)
    xticks.append(len(val)-0.5)
    rminy = min(y) ; rmaxy = max(y)
    if rminy >= 0.5:rminy = int(rminy - 0.5)
    if int(rmaxy) < 14:rmaxy = int (rmaxy) + 1
    yticks = []
    for i in range(rminy,rmaxy):
        yticks.append(i)
        yticks.append(i+0.5)
    yticks.append(rmaxy)
    #yticks = range(rminy,rmaxy+1,1)
    ax.plot(x,y)
    #set the time string
    ax.set_xticks(xticks)
    ax.set_xticklabels(ti,rotation=15)
    ax.set_yticks(yticks)

    #other setting
    plt.subplots_adjust(left=0.1, right=0.93, wspace=0.25, hspace=0.45,top=0.94,bottom=0.15)

    plt.xlabel('time')
    plt.ylabel('pH')
    plt.grid(True)
    plt.title('pH measurment '+sttime)



    plt.show()



if __name__ == '__main__': #test
    import time
    import random
    va = [];ti = [];st = time.strftime("%Y/%m/%d",time.localtime())
    for i in range(0,10):
        va.append(random.uniform(1.0,11.0))
        #time.sleep(1)
        ti.append(time.strftime('%H:%M:%S',time.localtime(i)))
    display_val_time(va,ti,st)


